<!-- $Id: warehouse_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->
{include file="pageheader.htm"}
{insert_scripts files="validator.js,../js/transport.org.js,../js/region.js"}
<div class="main-div">
<form method="post" action="rg_warehouse.php" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table cellspacing="1" cellpadding="3" width="100%">
  <tr>
    <td class="label">{$lang.label_w_name}</td>
    <td><input type="text" name="w_name" maxlength="60" value="{$warehouse.w_name}" />{$lang.require_field}</td>
  </tr>
  <tr>
    <td class="label">{$lang.label_w_desc}</td>
    <td><textarea  name="w_desc" cols="60" rows="4"  >{$warehouse.w_desc}</textarea></td>
  </tr>
  <tr>
    <td class="label">该仓库管辖的店铺：</td>
    <td id="storeCell">{foreach from=$warehouse.store_list item=store}
        <input type="checkbox" name="stores[]" value="{$store.id}" checked="true" />
        {$store.name}&nbsp;&nbsp;
      {/foreach} </td>
  </tr>
</table>
<hr>
<table cellspacing="1" cellpadding="3" width="100%">
  <caption><strong>从下面的列表中选择地区，点加号按钮添加到该仓库管辖的店铺</strong></caption>
  <tr>
    <td width="10%">&nbsp;</td>
    <td>{$lang.label_country}</td>
    <td>{$lang.label_province}</td>
    <td>{$lang.label_city}</td>
    <td>{$lang.label_district}</td>
    <td>门店列表:</td>
    <td width="10%">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><select name="country" id="selCountries" onChange="region.changed(this, 1, 'selProvinces')" size="10">
      {foreach from=$countries item=country name="fe_country"}
        <option value="{$country.region_id}" {if $smarty.foreach.fe_country.first}selected{/if}>{$country.region_name|escape:html}</option>
      {/foreach}
    </select></td>
    <td><select name="province" id="selProvinces" onChange="region.changed(this, 2, 'selCities')" size="10">
      <option value="">{$lang.select_please}</option>
    </select></td>
    <td><select name="city" id="selCities" onChange="region.changed(this, 3, 'selDistricts')" size="10">
      <option value="">{$lang.select_please}</option>
    </select></td>
    <td><select name="district" id="selDistricts" onChange="get_Store(this)" size="10">
      <option value="">{$lang.select_please}</option>
    </select></td>
    <td><select name="store" id="selStore" size="10">
      <option value="">{$lang.select_please}</option>
    </select></td>
    <td><input type="button" value="+" class="button" onclick="addRegion()" /></td>
  </tr>
</table>

<table align="center">
  <tr>
    <td colspan="2" align="center">
      <input type="submit" class="button" value="{$lang.button_submit}" />
      <input type="reset" class="button" value="{$lang.button_reset}" />
      <input type="hidden" name="act" value="{$form_action}" />
      <input type="hidden" name="id" value="{$warehouse.w_id}" />
    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="JavaScript">
<!--
region.isAdmin = true;
document.forms['theForm'].elements['w_name'].focus();
onload = function()
{
    var selCountry = document.forms['theForm'].elements['country'];
    if (selCountry.selectedIndex >= 0)
    {
        region.loadProvinces(selCountry.options[selCountry.selectedIndex].value);
    }
    // 开始检查订单
    startCheckOrder();
}
/**
 * 检查表单输入的数据
 */
function validate()
{
    validator = new Validator("theForm");
    validator.required("w_name",  no_warehousename);
    return validator.passed();
}

function get_Store(obj){
	var id_dist = obj.options[obj.selectedIndex].value;
	if(id_dist) Ajax.call('rg_warehouse.php', 'act=getStore&id_dist=' + id_dist , get_StoreResponse, "GET", "JSON");
}

function get_StoreResponse(result){
	var sel = document.getElementById("selStore");
	sel.length = 1;
	sel.selectedIndex = 0;
	if (result.store){
		for (i = 0; i < result.store.length; i ++ ){
			var opt = document.createElement("OPTION");
      		opt.value = result.store[i].id;
      		opt.text  = result.store[i].name;

      		sel.options.add(opt);
    	}
  	}
}

/**
 * 添加一个区域
 */
function addRegion()
{
    var selCountry  = document.forms['theForm'].elements['country'];
    var selProvince = document.forms['theForm'].elements['province'];
    var selCity     = document.forms['theForm'].elements['city'];
    var selDistrict = document.forms['theForm'].elements['district'];
    var storeCell  = document.getElementById("storeCell");
    var store = document.forms['theForm'].elements['store'];

	var storeId = 0;
	if (store.selectedIndex > 0){
        storeId = store.options[store.selectedIndex].value;
        storeName = store.options[store.selectedIndex].text;
    }else{
		if (selDistrict.selectedIndex > 0)
		{
			regionId = selDistrict.options[selDistrict.selectedIndex].value;
			regionName = selDistrict.options[selDistrict.selectedIndex].text;
		}
		else
		{
			if (selCity.selectedIndex > 0)
			{
				regionId = selCity.options[selCity.selectedIndex].value;
				regionName = selCity.options[selCity.selectedIndex].text;
			}
			else
			{
				if (selProvince.selectedIndex > 0)
				{
					regionId = selProvince.options[selProvince.selectedIndex].value;
					regionName = selProvince.options[selProvince.selectedIndex].text;
				}
				else
				{
					if (selCountry.selectedIndex >= 0)
					{
						regionId = selCountry.options[selCountry.selectedIndex].value;
						regionName = selCountry.options[selCountry.selectedIndex].text;
					}
					else
					{
						return;
					}
				}
			}
		}
	}
	
    // 检查该地区是否已经存在
    exists = false;
	if(!storeId){
		exists = true;
		alert("请选择相应的店铺！");
	}
    for (i = 0; i < document.forms['theForm'].elements.length; i++)
    {
      if (document.forms['theForm'].elements[i].type=="checkbox" && document.forms['theForm'].elements[i].name.substr(0, 5) == 'store')
      {
        if (document.forms['theForm'].elements[i].value == storeId)
        {
          exists = true;
          alert("该店铺已经存在！");
          break;
        }
      }
    }

    // 创建checkbox
    if (!exists)
    {
      storeCell.innerHTML += "<input type='checkbox' name='stores[]' value='" + storeId + "' checked='true' /> " + storeName + "&nbsp;&nbsp;";
    }
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}